<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>在线论坛</title>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../elementui/elementui.css">
  <link rel="stylesheet" href="../../css/font-awesome.min.css">
  <style>
  .section {
    width: 900px;
    margin: 0 auto;
  }

  .section-content {
    display: flex;
    justify-content: space-between;
    line-height: 60px;
    cursor: pointer;
    box-sizing: border-box;
    padding: 0 10px;
  }
  .section-content:hover {
    background-color: #E4E7ED;
    color: #fff;
  }
  .item-style {
    color: #909399;
    font-weight: 400;
  }
  .section-btn {
    text-align: right;
    margin-bottom: 15px;
    padding-right: 10px;
  }
  
  .forum-preview .el-form-item .el-form-item__content {
    display: flex;
    align-items: center;
  }
  
  .forum-preview .el-form-item .el-input .el-input__inner {
    border: 1px solid #eee;
    border-radius: 4px;
    padding: 0 10px;
    margin: 0;
    outline: none;
    color: #333;
    width: 280px;
    font-size: 14px;
    line-height: 36px;
    height: 36px;
  }
  
  .forum-preview .searchBtn {
    cursor: pointer;
    border: 0;
    border-radius: 4px;
    padding: 0px 15px;
    margin: 0 10px 0 0;
    outline: none;
    color: #fff;
    background: #F5BB00;
    width: auto;
    font-size: 14px;
    line-height: 36px;
    height: 36px;
    transition: all 0.3s;
  }
  
  .forum-preview .searchBtn:hover {
    background: #F5BB0090;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(245, 187, 0, 0.3);
  }
  
  .forum-preview .pubBtn {
    cursor: pointer;
    border: 0;
    border-radius: 4px;
    padding: 0px 15px;
    margin: 0 10px 0 0;
    outline: none;
    color: #fff;
    background: #333;
    width: auto;
    font-size: 14px;
    line-height: 36px;
    height: 36px;
    transition: all 0.3s;
  }
  
  .forum-preview .pubBtn:hover {
    background: #33333390;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  
  .forum-preview .z-box .section-content {
    cursor: pointer;
    padding: 0 20px;
    color: #333;
    background: #fff;
    display: flex;
    width: 100%;
    border-color: #ddd;
    border-width: 0 0 1px 0;
    line-height: 40px;
    align-items: center;
    border-style: dashed;
    height: 40px;
    transition: all 0.3s;
  }
  
  .forum-preview .z-box .section-content:hover {
    color: #333;
    background: #f5f5f5;
    transform: translateX(5px);
    border-left: 3px solid #F5BB00;
    padding-left: 25px;
  }
  
  /* 论坛列表容器样式 */
  .forum-container {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05);
    padding: 20px;
    margin-top: 20px;
  }
  
  .forum-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 20px;
    color: #333;
    border-bottom: 2px solid #F5BB00;
    padding-bottom: 10px;
  }
  
  /* 分页样式优化 */
  #pagination.el-pagination {
    text-align: center;
    margin-top: 30px;
  }
  
  #pagination.el-pagination .el-pagination__total {
    margin: 0 10px 0 0;
    color: #666;
    font-weight: 400;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    height: 28px;
  }
  
  #pagination.el-pagination .btn-prev {
    border: none;
    border-radius: 2px;
    padding: 0;
    margin: 0 5px;
    color: #666;
    background: #f4f4f5;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    min-width: 35px;
    height: 28px;
  }
  
  #pagination.el-pagination .btn-next {
    border: none;
    border-radius: 2px;
    padding: 0;
    margin: 0 5px;
    color: #666;
    background: #f4f4f5;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    min-width: 35px;
    height: 28px;
  }
  
  #pagination.el-pagination .btn-prev:disabled {
    border: none;
    cursor: not-allowed;
    border-radius: 2px;
    padding: 0;
    margin: 0 5px;
    color: #C0C4CC;
    background: #f4f4f5;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    height: 28px;
  }
  
  #pagination.el-pagination .btn-next:disabled {
    border: none;
    cursor: not-allowed;
    border-radius: 2px;
    padding: 0;
    margin: 0 5px;
    color: #C0C4CC;
    background: #f4f4f5;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    height: 28px;
  }
  
  #pagination.el-pagination .el-pager {
    padding: 0;
    margin: 0;
    display: inline-block;
    vertical-align: top;
  }
  
  #pagination.el-pagination .el-pager .number {
    cursor: pointer;
    padding: 0 4px;
    margin: 0 5px;
    color: #666;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    border-radius: 2px;
    background: #f4f4f5;
    text-align: center;
    min-width: 30px;
    height: 28px;
  }
  
  #pagination.el-pagination .el-pager .number:hover {
    cursor: pointer;
    padding: 0 4px;
    margin: 0 5px;
    color: #fff;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    border-radius: 2px;
    background: #F5BB00;
    text-align: center;
    min-width: 30px;
    height: 28px;
  }
  
  #pagination.el-pagination .el-pager .number.active {
    cursor: default;
    padding: 0 4px;
    margin: 0 5px;
    color: #FFF;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    border-radius: 2px;
    background: #F5BB00;
    text-align: center;
    min-width: 30px;
    height: 28px;
  }
  
  #pagination.el-pagination .el-pagination__sizes {
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    height: 28px;
  }
  
  #pagination.el-pagination .el-pagination__sizes .el-input {
    margin: 0 5px;
    width: 100px;
    position: relative;
  }
  
  #pagination.el-pagination .el-pagination__sizes .el-input .el-input__inner {
    border: 1px solid #DCDFE6;
    cursor: pointer;
    padding: 0 25px 0 8px;
    color: #606266;
    display: inline-block;
    font-size: 13px;
    line-height: 28px;
    border-radius: 3px;
    outline: 0;
    background: #FFF;
    width: 100%;
    text-align: center;
    height: 28px;
  }
  
  #pagination.el-pagination .el-pagination__sizes .el-input span.el-input__suffix {
    top: 0;
    position: absolute;
    right: 0;
    height: 100%;
  }
  
  #pagination.el-pagination .el-pagination__sizes .el-input .el-input__suffix .el-select__caret {
    cursor: pointer;
    color: #C0C4CC;
    width: 25px;
    font-size: 14px;
    line-height: 28px;
    text-align: center;
  }
  
  #pagination.el-pagination .el-pagination__jump {
    margin: 0 0 0 24px;
    color: #606266;
    display: inline-block;
    vertical-align: top;
    font-size: 13px;
    line-height: 28px;
    height: 28px;
  }
  
  #pagination.el-pagination .el-pagination__jump .el-input {
    border-radius: 3px;
    padding: 0 2px;
    margin: 0 2px;
    display: inline-block;
    width: 50px;
    font-size: 14px;
    line-height: 18px;
    position: relative;
    text-align: center;
    height: 28px;
  }
  
  #pagination.el-pagination .el-pagination__jump .el-input .el-input__inner {
    border: 1px solid #DCDFE6;
    cursor: pointer;
    padding: 0 3px;
    color: #606266;
    display: inline-block;
    font-size: 14px;
    line-height: 28px;
    border-radius: 3px;
    outline: 0;
    background: #FFF;
    width: 100%;
    text-align: center;
    height: 28px;
  }
  
  /* 抽取的行内样式 */
  .main-container {
    padding: 25px 7%;
    margin: 0 auto 40px;
    background: #fff;
  }
  
  .nav-header {
    width: 100%;
    line-height: 54px;
    text-align: center;
    background: #333;
    height: 54px;
    border-radius: 8px 8px 0 0;
  }
  
  .nav-title {
    padding: 0 20px;
    color: #fff;
    text-align: center;
    background: none;
    display: inline-block;
    width: auto;
    font-size: 20px;
  }
  
  .forum-item-title {
    color: #333;
    font-size: 16px;
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
  }
  
  .forum-item-time {
    color: #666;
    font-size: 14px;
  }
  
  .forum-item {
    border: 1px solid #eee;
    border-radius: 6px;
    margin-bottom: 10px;
    background-color: #f9f9f9;
  }
  </style>
</head>

<body>
  <div id="app">
    <div class="main-container">
      <div class="nav-header">
        <div class="nav-title">在线论坛</div>
      </div>
      <div class="forum-container forum-preview">
        <div class="forum-title">论坛主题</div>
        <el-form :inline="true" :model="searchForm" class="top-search">
          <el-form-item>
            <el-input v-model="searchForm.title" placeholder="请输入标题"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="getList" class="searchBtn">
              <i class="el-icon-search"></i>
              搜索
            </el-button>
            <el-button class="pubBtn" @click="addForum">
              <i class="el-icon-plus"></i>
              发布帖子
            </el-button>
          </el-form-item>
        </el-form>
        <div class="z-box">
          <div class="section-content forum-item" v-for="(item,index) in dataList" :key="index" @click="toDetail(item.id)">
            <div class="forum-item-title">{{item.title}}</div>
            <div class="forum-item-time">{{item.addtime}}</div>
          </div>
        </div>
        <el-pagination
          id="pagination"
          background
          layout="total, prev, pager, next, jumper"
          :current-page="pagination.page"
          :page-size="pagination.limit"
          :total="total"
          @current-change="pageChange">
        </el-pagination>
      </div>
    </div>
  </div>

  <!-- 引入JS -->
  <script src="../../js/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  <script src="../../elementui/elementui.js"></script>
  <script>
    var app = new Vue({
      el: '#app',
      data() {
        return {
          searchForm: {
            title: ''
          },
          dataList: [],
          total: 0,
          pagination: {
            page: 1,
            limit: 10
          }
        }
      },
      created() {
        this.getList();
      },
      methods: {
        getList() {
          let params = {
            page: this.pagination.page, 
            limit: this.pagination.limit, 
            isdone: '开放', 
            sort: 'istop,toptime', 
            order: 'desc,desc'
          };
          
          let searchWhere = {};
          if(this.searchForm.title != '') {
            searchWhere.title = '%' + this.searchForm.title + '%';
          }
          
          axios.get('http://localhost:8080/springboot1a8gh/forum/flist', {
            params: Object.assign(params, searchWhere)
          },{
            headers: {
              'Token': localStorage.getItem("Token")
            }
          }).then(res => {
            if (res.data.code == 0) {
              this.dataList = res.data.data.list;
              this.total = res.data.data.total;
              this.pagination.limit = res.data.data.pageSize;
            }
          });
        },
        pageChange(page) {
          this.pagination.page = page;
          this.getList();
        },
        addForum() {
          window.location.href = 'add.html';
        },
        myForum() {
          window.location.href = './myForumList.html';
        },
        toDetail(id) {
          window.location.href = './detail.html?id=' + id;
        }
      }
    });
  </script>
</body>
</html>
